<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://unpkg.com/vuex@3.1.3/dist/vuex.js"></script>
    <script>
      const counter1 = {
        namespaced: true,
        state: { count: 1 },
        mutations: {
          increase(state) {
            state.count++;
          },
        },
        actions: {
          increase(context) {
            context.commit("increase");
            context.commit("changeName", { name: "front" },{root:true});
          },
          increase2:{
            root:true,
            handler(context){
              context.commit("increase");
            }
          }
        },
      };

      const store = new Vuex.Store({
        state: { name: "zhufeng" },
        mutations: {
          changeName(state, payload) {
            state.name = payload.name;
          },
        },
        modules: {
          counter1,
        },
      });
      var vm = new Vue({
        el: "#app",
        store,
      });
    </script>
  </body>
</html>
